package com.partsoft.dits.log;

/**
 * 日志类型
 */
public enum LogType {

	/**
	 * 系统日志
	 */
	SYSTEM("系统", 1),
	
	/**
	 * 应用日志(例如集成)
	 */
	APPS("应用", 2),
	
	/**
	 * 用户操作日志
	 */
	USER("用户", 3),
	
	/**
	 * 其他
	 */
	OTHER("其他", 9);
	
	
	private final int code;
	
	private final String title;
	
	private LogType(String title, int code) {
		this.title = title;
		this.code = code;
	}
	
	public int getCode() {
		return code;
	}
	
	public String getTitle() {
		return title;
	}
	
	@Override
	public String toString() {
		return getTitle();
	}
	
	public static LogType fromName(String name) {
		for (LogType value : LogType.values()) {
			if (value.name().equalsIgnoreCase(name)) return value;
		}
		return OTHER;
	}
	
	public static LogType fromCode(int code) {
		for (LogType value : LogType.values()) {
			if (value.code == code) return value;
		}
		return OTHER;
	}
	
}
